using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Info.Basic;

using EntLibEC.Biz;
using EntLibEC.Biz.Basic;

namespace EntLibEC.View.Basic
{
	/// <summary>
	/// Summary description for CurrencySearch.
	/// </summary>
	public partial class CurrencySearch : PageBase
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			btnAdd.Attributes["onclick"]= "javascript:openWindowS3('CurrencyOpt.aspx?opt=add'); return false;";
			if (!Page.IsPostBack)
				BindGrid();
		}

		private void BindGrid()
		{
			DataTable dt = BuildTable();
			DataGrid1.DataSource = dt;
			DataGrid1.DataBind();
			int rows = 0;
			if ( Util.HasMoreRow(dt) )
				rows = dt.Rows.Count;
			Assert(lblMessage, rows.ToString() + " record(s)", 1);
		}
		private DataTable BuildTable()
		{
			DataTable table = new DataTable("Currency");
			table.Columns.Add(new DataColumn("SysNo",typeof(int)));
			table.Columns.Add(new DataColumn("CurrencyID",typeof(string)));
			table.Columns.Add(new DataColumn("CurrencyName",typeof(string)));
			table.Columns.Add(new DataColumn("CurrencySymbol",typeof(string)));
			table.Columns.Add(new DataColumn("IsLocal",typeof(string)));
			table.Columns.Add(new DataColumn("ExchangeRate",typeof(string)));
			table.Columns.Add(new DataColumn("ListOrder",typeof(string)));
			table.Columns.Add(new DataColumn("Status", typeof(string)));
			
			SortedList sl = CurrencyManager.GetInstance().GetCurrencyList();
			if ( sl == null )
				return table;

			foreach(CurrencyInfo item in sl.Keys)
			{
				DataRow row = table.NewRow();
				row["SysNo"] = item.SysNo;
				row["CurrencyID"] = item.CurrencyID;
				row["CurrencyName"] = "<a href=\"javascript:openWindowS3('CurrencyOpt.aspx?sysno=" + item.SysNo.ToString() + "&opt=update')" + "\">" + item.CurrencyName + "</a>";
				row["CurrencySymbol"] = item.CurrencySymbol;
				row["IsLocal"] = AppEnum.GetYNStatus(item.IsLocal);
				row["ExchangeRate"] = item.ExchangeRate.ToString(AppConst.DecimalFormat);
				row["ListOrder"] = item.ListOrder;
				row["Status"] = AppEnum.GetBiStatus(item.Status);

				table.Rows.Add(row);
			}
			return table;

		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnSearch_Click(object sender, System.EventArgs e)
		{
			BindGrid();
		}
	}
}
